package com.zimmor.mq.rocket_train.base;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

/**
 * @Author:zimmor
 * @Date: 2023/2/10 17:08
 * @Description 发送单方向普通消息
 * @version: 1.0.0
 */

public class OneWayProducer {
    public static void main(String[] args) throws MQClientException {
        //创建producer
        DefaultMQProducer producer3 = new DefaultMQProducer("producer-group1");
        //设置namesrv
        producer3.setNamesrvAddr("192.168.204.136:9876;192.168.204.137:9876");
        //启动producer
        producer3.start();
        //构建message
        for (int i = 0; i < 10 ; i++) {
            Message message = new Message("base1", "tag1", ("oneWay-message"+i).getBytes());
            try {
                //发送消息
                producer3.sendOneway(message);
            } catch (RemotingException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        //关闭producer
        producer3.shutdown();
    }
}
